﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ZHDJ.MobileInterface
{
    public partial class GetSystemBranch : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            GetSystemBranchOutParam result = new GetSystemBranchOutParam();
            GetSystemBranchInParam param = new GetSystemBranchInParam();
            string logMsg = "";
            bool isFlag = true;

            try
            {
                param = inParam as GetSystemBranchInParam;

                if (isFlag)
                {
                    DataSet ds = InterfaceHelper.GetSystemBranchData(param.BranchID, param.ModifyTime, param.page_no, param.page_count,param.CreateTime);

                    if (ds != null && ds.Tables.Count == 2)
                    {
                        BranchData itemTemp;
                        result.dataList.total_pages = CommonUtils.GetTotalPages(Convert.ToInt32(ds.Tables[0].Rows[0][0]), param.page_count);
                        foreach (DataRow dr in ds.Tables[1].Rows)
                        {
                            itemTemp = new BranchData();
                            itemTemp.BranchID = dr["BranchID"].ToString();
                            itemTemp.BranchName = dr["BranchName"].ToString();
                            itemTemp.ParentBranchID = dr["ParentBranchID"].ToString();
                            itemTemp.OrderNo = dr["OrderNo"].ToString();
                            itemTemp.Description = dr["Description"].ToString();
                            itemTemp.Address = dr["Address"].ToString();
                            itemTemp.LinkMan = dr["LinkMan"].ToString();
                            itemTemp.LinkPhone = dr["LinkPhone"].ToString();
                            itemTemp.BranchMark = dr["BranchMark"].ToString();
                            itemTemp.SocialParty = dr["SocialParty"].ToString();
                            itemTemp.CreateTime = dr["CreateTimeEx"].ToString();
                            itemTemp.ModifyTime = dr["ModifyTimeEx"].ToString();
                            result.dataList.Data.Add(itemTemp);
                        }
                    }
                }
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员";
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode + "-GetSystemBranch", SerializeHelper.JsonSerializer<GetSystemBranchInParam>(param), logMsg);
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<GetSystemBranchInParam, GetSystemBranchOutParam>();
            else
                SafeProcessRequest<GetSystemBranchInParam, GetSystemBranchOutParam>();
        }
    }


    #region 请求参数
    public class GetSystemBranchInParam
    {
        /// <summary>
        /// 修改时间
        /// </summary>
        public string ModifyTime
        { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public string CreateTime
        { get; set; }

        /// <summary>
        /// 组织ID
        /// </summary>
        public string BranchID
        { get; set; }

        /// <summary>
        /// 必填 当前页
        /// </summary>
        public int page_no
        { get; set; }

        /// <summary>
        /// 必填，每页记录条数
        /// </summary>
        public int page_count
        { get; set; }
    }
    #endregion

    #region 结果参数
    public class GetSystemBranchOutParam
    {
        public GetSystemBranchOutParam()
        {
            code = "1";
            desc = "操作成功";
            dataList = new BranchDataList();
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }

        public BranchDataList dataList
        { get; set; }



    }
    #region 获取组织列表
    public class BranchDataList
    {
        public BranchDataList()
        {
            total_pages = 0;
            Data = new List<BranchData>();
        }

        public List<BranchData> Data { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        public int total_pages
        { get; set; }
    }

    /// <summary>
    /// 组织详细信息
    /// </summary>
    public class BranchData
    {
        /// <summary>
        /// 组织ID
        /// </summary>
        public string BranchID
        { get; set; }
        /// <summary>
        /// 组织名
        /// </summary>
        public string BranchName
        { get; set; }

        /// <summary>
        /// 父组织ID
        /// </summary>
        public string ParentBranchID
        { get; set; }

        /// <summary>
        /// 组织序号
        /// </summary>
        public string OrderNo
        { get; set; }

        /// <summary>
        /// 组织说明
        /// </summary>
        public string Description
        { get; set; }

        /// <summary>
        /// 组织地址
        /// </summary>
        public string Address
        { get; set; }

        /// <summary>
        /// 组织联系人
        /// </summary>
        public string LinkMan
        { get; set; }

        /// <summary>
        /// 组织联系电话
        /// </summary>
        public string LinkPhone
        { get; set; }

        /// <summary>
        /// 组织层级
        /// </summary>
        public string BranchMark
        { get; set; }

        /// <summary>
        /// 组织类型
        /// </summary>
        public string SocialParty
        { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public string CreateTime
        { get; set; }

        /// <summary>
        /// 修改时间
        /// </summary>
        public string ModifyTime
        { get; set; }
    }
    #endregion



    #endregion
}